const API = require('../../pages/api/index')
const {
  typeJson
} = require('../../utils/typejson')
let prolist = wx.getStorageSync('prolist') == '' ? wx.getStorageSync('prolist') : JSON.parse(wx.getStorageSync('prolist'))

const {
  get,
  post,
  put
} = require('../../request/index')


Page({

  /**
   * 页面的初始数据
   */
  data: {
    flowDetailsItem: {},
    showCheck: false, // 显示审核人员信息
    pulldown: "",
    pullup: 2,
    addButton: false,
    active: 0,
    prolist: wx.getStorageSync('prolist') == '' ? wx.getStorageSync('prolist') : JSON.parse(wx.getStorageSync('prolist')),
    alarm1: [],
    alarm2: [],
    alarm3: [],
    flowDetails: [],
    show: false,
    show1: false,
    flowNo: null,
    id: null,
    sign: null,
    content: "",
    jsonType: [{
      label: "通过",
      value: 3
    }, {
      label: "不通过",
      value: 4
    }],
    approStatus: null,
    names: null,
    cardType: null,
    beginTime: null,
    endTime: null,
    contenct: null,
    pageNum: 1,
    pageSize: 99999999999,





  },
  add() {
    wx.navigateTo({
      url: `/pages/control/control`,
    })
  },
  // 去审核
  examine(e) {
    console.log(e.target.dataset.flowdetails);
    let {
      flowNo,
      names,
      cardType,
      beginTime,
      endTime,
      contenct,
      id
    } = e.target.dataset.flowdetails
    this.setData({
      flowNo,
      id,
      names,
      cardType,
      beginTime,
      endTime,
      contenct,
      show1: true
    })
  },
  canvasChang(e) {
    this.setData({
      sign: e.detail
    })
  },
  changeTextarea(e) {
    this.setData({
      content: e.detail
    })
  },
  changeSelect(e) {

    this.setData({
      status: e.detail
    })
  },
  // 确定修改审批
  smt() {
    let {
      flowNo,
      id,
      sign,
      status,
      content,
      prolist
    } = this.data
    put('/app/balstLibrary', {
      flowNo,
      id,
      sign,
      status,
      content,
      auditUserId: prolist.userId
    }).then(res => {
      console.log(res);
      if (res.code == 200) {
        this.setData({
          show: false,
          show1: false
        })
        this.change2();
      }
    })
  },
  onChange(event) {
    console.log(event);
    switch (event.detail.index) {
      case 0:
        this.change1()
        break;
      case 1:
        this.change2()
        break;
      case 2:
        this.change3()
        break;

      default:
        break;
    }
  },

  //我发起
  async change1() {
    let {
      pageNum,
      pageSize,
      prolist
    } = this.data
    const res = await post('/app/balstLibrary/getList', {
      userId: prolist.userId,
      type: 2,
      pageNum,
      pageSize
    })
    console.log(res);
    if (res.code == 200) {
      this.setData({
        alarm1: res.rows
      })
    }

  },
  //待审核
  async change2() {
    let {
      pageNum,
      pageSize,
      prolist
    } = this.data
    const res = await get(`/app/balstLibrary/listByMyslef/${prolist.userId}?pageNum=${pageNum}&pageSize=${pageSize}`)
    if (res.code == 200) {
      this.setData({
        alarm2: res.rows
      })
    }
  },
  // 已通过
  async change3() {
    let {
      pageNum,
      pageSize,
      prolist
    } = this.data
    const res = await post('/app/balstLibrary/getList', {
      userId: prolist.userId,
      type: 2,
      pageNum,
      pageSize,
      approStatus: 2
    })
    if (res.code == 200) {
      this.setData({
        alarm3: res.rows
      })
    }
  },
  // 查看
  look(e) {

    let item = e.target.dataset.flowdetails
    this.setData({
      show: true,
      flowDetailsItem: item,
      approStatus: item.approStatus,
      flowDetails: item.flowDetails
    })



  },
  // 显示审核信息
  showDetail() {
    this.setData({
      showCheck: !this.data.showCheck
    })
  },
  onClose() {
    this.setData({
      show: false,
      show1: false,
      showCheck: false, // 显示审核人员信息
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.change1()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

    this.setData({
      showCom: false
    });
    this.setData({
      showCom: true
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    return
    console.log('触底了----');
    // this.setData({
    //   pullup: this.data.pullup + 1
    // })
  },



  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})